package test;

import java.util.Scanner;
import java.util.Random;
public class test {
        public static String generateVerificationCode(int length) {
            String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            Random random = new Random();
            StringBuilder code = new StringBuilder();

            for (int i = 0; i < length; i++) {
                int index = random.nextInt(characters.length());
                code.append(characters.charAt(index));
            }
            return code.toString();
        }

        public static void main(String[] args) {
            String verificationCode = generateVerificationCode(4);
            System.out.println("生成的验证码: " + verificationCode);

            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入验证码: ");
            String userInput = scanner.nextLine().trim();

            if (userInput.equalsIgnoreCase(verificationCode)) {
                System.out.println("验证码正确！");
            } else {
                System.out.println("验证码错误！");
            }

            scanner.close();
        }
}
